package com.qj.yantaishan.controller;

import java.util.List;
import com.baomidou.mybatisplus.extension.service.IService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.qj.yantaishan.common.annotation.Log;
import com.qj.yantaishan.common.enums.BusinessType;
import com.qj.yantaishan.domain.OrderPeerpay;
import com.qj.yantaishan.service.IOrderPeerpayService;
import com.qj.yantaishan.common.core.controller.BaseController;
import com.qj.yantaishan.common.core.domain.AjaxResult;
import com.qj.yantaishan.common.utils.poi.ExcelUtil;
import com.qj.yantaishan.common.core.page.TableDataInfo;

/**
 * 代付Controller
 * 
 * @author qihe
 * @date 2022-07-22
 */
@RestController
@RequestMapping("/yantaishan/OrderPeerpay")
public class OrderPeerpayController extends BaseController
{
    private String prefix = "yantaishan/OrderPeerpay";

    @Autowired
    private IOrderPeerpayService orderPeerpayService;

    @RequiresPermissions("yantaishan:peerpay:view")
    @GetMapping()
    public String peerpay()
    {
        return prefix + "/peerpay";
    }

    /**
     * 查询代付列表
     */
    @RequiresPermissions("yantaishan:peerpay:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(OrderPeerpay orderPeerpay)
    {
        startPage();
        List<OrderPeerpay> list = orderPeerpayService.selectOrderPeerpayList(orderPeerpay);
        return getDataTable(list);
    }

    /**
     * 导出代付列表
     */
    @RequiresPermissions("yantaishan:peerpay:export")
    @Log(title = "代付", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(OrderPeerpay orderPeerpay)
    {
        List<OrderPeerpay> list = orderPeerpayService.selectOrderPeerpayList(orderPeerpay);
        ExcelUtil<OrderPeerpay> util = new ExcelUtil<OrderPeerpay>(OrderPeerpay.class);
        return util.exportExcel(list, "代付数据");
    }

    /**
     * 新增代付
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存代付
     */
    @RequiresPermissions("yantaishan:peerpay:add")
    @Log(title = "代付", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(OrderPeerpay orderPeerpay)
    {
        return toAjax(orderPeerpayService.insertOrderPeerpay(orderPeerpay));
    }

    /**
     * 修改代付
     */
    @RequiresPermissions("yantaishan:peerpay:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        OrderPeerpay orderPeerpay = orderPeerpayService.selectOrderPeerpayById(id);
        mmap.put("orderPeerpay", orderPeerpay);
        return prefix + "/edit";
    }

    /**
     * 修改保存代付
     */
    @RequiresPermissions("yantaishan:peerpay:edit")
    @Log(title = "代付", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(OrderPeerpay orderPeerpay)
    {
        return toAjax(orderPeerpayService.updateOrderPeerpay(orderPeerpay));
    }

    /**
     * 删除代付
     */
    @RequiresPermissions("yantaishan:peerpay:remove")
    @Log(title = "代付", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(orderPeerpayService.deleteOrderPeerpayByIds(ids));
    }
}
